package org.afs.gescol.gwt.server.service.mock;

import java.util.ArrayList;
import java.util.List;

import org.afs.gescol.gwt.shared.EleveModel;
import org.afs.gescol.gwt.shared.PersonnelModel;
import org.afs.gescol.gwt.shared.SearchCriteriaModel;
import org.scub.foundation.framework.gwt.module.shared.pagination.RemotePagingCriteriasModel;
import org.scub.foundation.framework.gwt.module.shared.pagination.RemotePagingResultsModel;

public class GetServicesMock {

    public static final String[] PROFS =
            new String[]{"M. SOGBO Kokou", "M. MESSAN Dela", "M. ADJE Kodjo", "Mme HOFFER Lys", "M. GBENYO Kobla", "M. GBENYO Koffi",
        "M. FOLIKOUE Kossi", "Mme AHOVI Serafin", "M. LAWSON Adjé", "M. TEKA Alain", "Mme KPADENOU Joelle", "M. SENAH Têtê"};

    public static final String[] ELEVS =
            new String[]{"M. AGLI Ayao", "Mlle. AGBOGAN Dela", "M. AHLISSOU Kodjo", "Mme AKAKPO Affiwa", "M. BOBO Akouvi", "M. AMOUZOU Koffi",
        "M. DOGBE Etodji", "Mme HOUNTODJI Serafin", "M. OCLOO Komi", "M. KPOGNON François", "Mme EGLI Adjo", "M. FOLLY Justin", "Mlle. DJATA Abla", "Mlle. ANTHONY Colette"};

    public static RemotePagingResultsModel<EleveModel> getListElevesByCriterias(RemotePagingCriteriasModel<SearchCriteriaModel> criterias) {
        final RemotePagingResultsModel<EleveModel> res = new RemotePagingResultsModel<EleveModel>();
        final List<EleveModel> listResults = new ArrayList<EleveModel>();
        final List<EleveModel> listResultsTous = new ArrayList<EleveModel>();
         
        for (int i=0; i<ELEVS.length; i++) {
            final String[] data = ELEVS[i].split("\\s");
            final EleveModel elev = new EleveModel();
            elev.setId(Long.valueOf(i));
            elev.setNumber("EL000" + i);
            elev.setCivility((data[0].equals("M.")) ? "Monsieur" : "Mademoiselle");
            elev.setLastName(data[1]);
            elev.setFirstName(data[2]);
            listResultsTous.add(elev);
            if (criterias.getCriterias().getSearchWord() != null && !"".equals(criterias.getCriterias().getSearchWord())
                    && ELEVS[i].toLowerCase().contains(criterias.getCriterias().getSearchWord().toLowerCase())) {
                listResults.add(elev);
            }
        }
        if (criterias.getCriterias().getSearchWord() != null && !"".equals(criterias.getCriterias().getSearchWord())) {
            res.setListResults(listResults);
            res.setTotalResults(listResults.size());
        } else {
            res.setListResults(listResultsTous);
            res.setTotalResults(listResultsTous.size());
        }
        return res;
    }

    public static RemotePagingResultsModel<PersonnelModel> getListPersonnelsByCriterias(RemotePagingCriteriasModel<SearchCriteriaModel> criterias) {
        final RemotePagingResultsModel<PersonnelModel> res = new RemotePagingResultsModel<PersonnelModel>();
        final List<PersonnelModel> listResults = new ArrayList<PersonnelModel>();
        final List<PersonnelModel> listResultsTous = new ArrayList<PersonnelModel>();
         
        for (int i=0; i<PROFS.length; i++) {
            final String[] data = PROFS[i].split("\\s");
            final PersonnelModel pers = new PersonnelModel();
            pers.setId(Long.valueOf(i));
            pers.setNumber("MAT000" + i);
            pers.setCivility((data[0].equals("M.")) ? "Monsieur" : "Madame");
            pers.setLastName(data[1]);
            pers.setFirstName(data[2]);
            listResultsTous.add(pers);
            if (criterias.getCriterias().getSearchWord() != null && !"".equals(criterias.getCriterias().getSearchWord())
                    && PROFS[i].toLowerCase().contains(criterias.getCriterias().getSearchWord().toLowerCase())) {
                listResults.add(pers);
            }
        }
        if (criterias.getCriterias().getSearchWord() != null && !"".equals(criterias.getCriterias().getSearchWord())) {
            res.setListResults(listResults);
            res.setTotalResults(listResults.size());
        } else {
            res.setListResults(listResultsTous);
            res.setTotalResults(listResultsTous.size());
        }
        return res;
    }
}
